package com.wn.quality.web;

import com.wn.common.ResponseEntity;
import com.wn.entity.Hr;
import com.wn.entity.InventoryBookkeeping;
import com.wn.entity.Nonconformance;
import com.wn.entity.Project;
import com.wn.quality.mapper.HrMapper;
import com.wn.quality.mapper.InventoryBookkeepingMapper;
import com.wn.quality.mapper.ProjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author wuqingting
 * @date 2022/10/24
 */
@RestController
@RequestMapping("/quality/query")
public class AsynchronousQueryController {
    @Autowired
    private ProjectMapper projectMapper;
    @Autowired
    private InventoryBookkeepingMapper inventoryBookkeepingMapper;
    @Autowired
    private HrMapper hrMapper;

    @RequestMapping("/allProject")
    public ResponseEntity allProject(){
        List<Project> projectList = projectMapper.getAll();

        return new ResponseEntity(projectList);
    }

    @RequestMapping("/inven")
    public ResponseEntity inven(@RequestBody Nonconformance nonconformance){
        InventoryBookkeeping bookkeeping = inventoryBookkeepingMapper.getByCondition(nonconformance.getInventoryBookkeeping());
        if (bookkeeping==null){
            return new ResponseEntity("400","fail","库存物料不存在");
        }
        return new ResponseEntity(bookkeeping.getId());
    }

    @RequestMapping("/processUser/{id}")
    public ResponseEntity processUser(@PathVariable int  id){
        List<Hr> hrList = hrMapper.getByRoleId(id);

        return new ResponseEntity(hrList);
    }


}
